@echo off
setlocal EnableDelayedExpansion

set PORT=80

REM 检查端口是否被占用，如果是则提示用户并退出
for /f "tokens=2" %%i in ('netstat -a -n -o ^| findstr /r /c:"^TCP.*:%PORT%.*LISTENING"') do (
    set PID=%%i
)
if defined PID (
    echo Error: Port %PORT% is already in use by process %PID%.
    pause
    exit /b 1
)

set ip=Not_Found
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /i "IPv4 Address"') do (
    set ip=%%a
    set ip=!ip:~1!
    goto foundIP
)

:notfound
echo Unable to determine IP Address.
exit /b 1

:foundIP
echo Your IP Address is: !ip!
echo Starting HTTP server on port %PORT%...
python -m http.server %PORT% --directory FileServer/

